/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



function validationNum(n) {

    return !isNaN(parseFloat(n));
}


function validateFinite(n){
    return isFinite(n);
}

function isSpclChar(n){
    var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
    for (var i = 0; i < n.length; i++) {
        if (iChars.indexOf(n.charAt(i)) != -1) {
            return false;
        }
    }
    return true;
}


function ValidatePostal(n) {
    // this function restricts to only numeric
    var currentValue = n.value;
    var lastEntered = currentValue.charAt((currentValue.length-1));
    if(validationNum(lastEntered) && validateFinite(lastEntered)){
        return true;
    }else{
        if(currentValue.length == 1){
            n.value = "";
        }else{
            currentValue = currentValue.substring(0,(currentValue.length-1));
            n.value = currentValue;
        }
        return true;
    }

}

function ValidateText(n){
    // only allows Text ONly.. No number, No Special characters
    var currentValue = n.value;
    var lastEntered = currentValue.charAt((currentValue.length-1));
    if(!validationNum(lastEntered) && isSpclChar(lastEntered)){

        return true;
    }else{

        if(currentValue.length == 1){
            n.value = "";
        }else{
            currentValue = currentValue.substring(0,(currentValue.length-1));
            n.value = currentValue;
        }
        return true;
    }
}

function ValidateEmail(n){
    var x=n.value;
    var atpos=x.indexOf("@");
    var dotpos=x.lastIndexOf(".");
    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
    {
        alert("Not a valid e-mail address");
        return false;
    }
    return true;
}


